package threadTest;

public class Pruduct {
      int sum = 0;

    synchronized public  void add() throws InterruptedException {
        if (this.sum>=10){
            this.wait();
        }
        sum++;
        Thread.sleep(1000);
        System.out.println(Thread.currentThread().getName()+ "   ："+sum);
        this.notifyAll();
    }

    synchronized public  void del() throws InterruptedException {
        if (this.sum<3){
            this.wait();
        }
        sum--;
        Thread.sleep(1000);
        System.out.println(Thread.currentThread().getName()+ "   ："+sum);
        this.notify();
    }

}
